<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace app\controllers;

use Yii;
use yii\web\Controller;
use yii\web\Response;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
date_default_timezone_set("PRC");
/**
 * This command echoes the first argument that you have entered.
 *
 * This command is provided as an example for you to learn how to create console commands.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class BaseController extends Controller
{
    /**
     * before action
     * @param  [type] $action [description]
     * @return [type]         [description]
     */
    public function beforeAction($action)
    {
        //权限检查
        if (!Yii::$app->user->isGuest) {
            $authKey = Yii::$app->user->identity->authKey;
        } else {
            $authKey = 'Guest';
        }
        //rute check
        if ('login' != $action->id) {
            //login check
            if ('Guest' == $authKey && 'login' != $action) {
                //跳登录
                return $this->redirect(['/site/login']);  
            }
        }
        return parent::beforeAction($action);
    }
}
